package com.my.test.java.two.moredata.datas;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;


public class HPreparedstatement extends AbsPreparedStatementCopy{
	
	private PreparedStatement stmt;
	private Connection conn;
	private String sql;
	private List<Object> list;
	
	public HPreparedstatement(){}
	public HPreparedstatement(Connection conn,String sql){
		try {
			this.sql = sql;
			this.stmt = conn.prepareStatement(sql);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	public HPreparedstatement(Connection conn,String sql,List<Object> list){
		try {
			this.conn = conn;
			this.sql = sql;
			this.list = list;
//			System.out.println("----"+sql);
//			this.stmt = conn.prepareStatement(sql);
//			this.stmt.setString(1, "test31");
//			String sqlPrin = sql+"  value=  ";
			
//			ResultSet rs = stmt.executeQuery();
//			while(rs.next()){
//				System.out.println("sharding---"+rs.getString("name"));
//			}
//			if(null!=list){
//        		for(int i=0;i<list.size();i++){
////        			this.stmt.setString(i+1, list.get(i).toString());
////        			if(i==1){
//        				this.stmt.setObject(i+1, list.get(i));
////        			}else{
////        			}
//        			sqlPrin = sqlPrin + list.get(i)+",";
//        		}
//        	}
//			System.out.println(sqlPrin);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
    public ResultSet executeQuery() throws SQLException {
    	ResultSet rs = null;
        try {
        	this.stmt = this.conn.prepareStatement(this.sql);
			this.stmt.setString(1, "test31");
            rs = this.stmt.executeQuery();
            if(rs.next()){
            	System.out.println("ok.....");
            	System.out.println(rs.getString("name"));
            }
        } catch (Throwable t) {
        	t.printStackTrace();
        } finally {
        	
        }
        return rs;
    }
    @Override
	public void setObject(int parameterIndex, Object x) throws SQLException {
    	this.stmt.setObject(parameterIndex, x);
	}
    @Override
	public void setString(int parameterIndex, String x) throws SQLException {
    	this.stmt.setString(parameterIndex, x);
	}
	
}
